from flask import Blueprint, request
from ..common.Token import certify_token, generate_token

base = Blueprint('base', __name__)
no_Auth = ['/api/getpublickey', '/api/login']

from ..routes import *
from ..music import *


# 请求拦截器
@base.before_request
def before():
    """
       针对app实例定义全局拦截器
       """
    url = request.path  # 读取到当前接口的地址
    header = request.headers
    isExpred = certify_token(header.get('Authorization', ''))
    if url in no_Auth:  # 拦截不需要验证的接口
        pass
    elif isExpred is False:
        return {
            'code': -9998,
            'data': '',
            'message': '登陆时间过期，请重新登录'
        }
    else:
        pass
